package  com.zzkj.util
{
	import mx.validators.DateValidator;
	import mx.validators.ValidationResult;

	public class DateFieldValidator extends DateValidator
	{
		[Property("slectedDate")]
		private var _slectedDate:Date;
		[Property("require")]
		private var _require:Boolean = false;
		private var results:Array;
		
		public function DateFieldValidator()
		{
			super();
			initProperies()
			
		}
		private function initProperies():void{
			allowedFormatChars = "-"; 
    		inputFormat = "yyyy-mm-dd";
    		wrongMonthError = "请确认输入的月份为1~12之间";
    		wrongDayError = "请为月份输入一个存在的号数"; 
    		wrongLengthError = "请输入正确的格式";
    		invalidCharError = "日期中存在无效字符";
    		requiredFieldError="日期不能为空";
		}
		
		override protected function doValidation(value:Object):Array {
			results = [];
 			results = super.doValidation(value); 
 			if(value!=null){
	            var y:String = value.toString().substring(0,4);
	            var m:String = value.toString().substring(5,7);
	            var d:String = value.toString().substring(8,10);
	            var yint:int = int(y);
	            var mint:int = int(m)-1;
	            var dint:int = int(d);
	            var date:Date=new Date(yint,mint,dint);
	            var currentDate:Date= new Date();
            
	            if(date < currentDate&&_require==true&&yint!=0){
	            	results.push(new ValidationResult(true, null, "Short", "你输入的时间过时了"));
	            	return results;
	            }
            	
 			}
            return results;
		}
		
		
		
		
		
		
		
		public function set slectedDate(date:Date):void {
			_slectedDate = date;
		}
		public function get slectedDate():Date {
			return _slectedDate;
		}

		public function set require(b:Boolean):void {
			_require = b;
		}
		public function get require():Boolean {
			return _require;
		}
		
		
		
	}
}